reduce the amount of panics in {TokenStream, Literal}::from_str calls#147859
reduce the amount of panics in {TokenStream, Literal}::from_str calls#147859cyrgani wants to merge 1 commit intorust-lang:mainfrom
{TokenStream, Literal}::from_str calls#147859Conversation
|
rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead. cc @rust-lang/rust-analyzer |
|
r? @davidtwco rustbot has assigned @davidtwco. Use |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
e2c0009 to
80b67bb
Compare
|
@rustbot ready |
ba098bc to
0274d78
Compare
|
This does not fix #58736 entirely yet: TokenStream::from_str("0b2");is still a compile error because it internally calls |
|
I'm not familiar enough with this part of the compiler r? compiler |
0274d78 to
13d3d06
Compare
This comment has been minimized.
This comment has been minimized.
TokenStream::from_str panics with LexErrors{TokenStream, Literal}::from_str calls
add larger test for `proc_macro` `FromStr` implementations Currently, there are only few tests that check the output of `TokenStream::from_str` and `Literal::from_str` (which is somewhat understandable as the rustc implementation just delegates these calls to the parser). In preparation for both the standalone backend (rust-lang#130856) which will probably need to reimplement this logic as well as for removing panics from these functions (rust-lang#58736), this PR adds a test which shows the various messy ways of how these functions report errors and the return values for successful parses. Followup PRs such as rust-lang#147859 will change more and more of these "diagnostic + error"s into `LexErrors`. The test structure with the extra module is used to allow reusing it later easily for the standalone backend.
add larger test for `proc_macro` `FromStr` implementations Currently, there are only few tests that check the output of `TokenStream::from_str` and `Literal::from_str` (which is somewhat understandable as the rustc implementation just delegates these calls to the parser). In preparation for both the standalone backend (rust-lang#130856) which will probably need to reimplement this logic as well as for removing panics from these functions (rust-lang#58736), this PR adds a test which shows the various messy ways of how these functions report errors and the return values for successful parses. Followup PRs such as rust-lang#147859 will change more and more of these "diagnostic + error"s into `LexErrors`. The test structure with the extra module is used to allow reusing it later easily for the standalone backend.
add larger test for `proc_macro` `FromStr` implementations Currently, there are only few tests that check the output of `TokenStream::from_str` and `Literal::from_str` (which is somewhat understandable as the rustc implementation just delegates these calls to the parser). In preparation for both the standalone backend (rust-lang#130856) which will probably need to reimplement this logic as well as for removing panics from these functions (rust-lang#58736), this PR adds a test which shows the various messy ways of how these functions report errors and the return values for successful parses. Followup PRs such as rust-lang#147859 will change more and more of these "diagnostic + error"s into `LexErrors`. The test structure with the extra module is used to allow reusing it later easily for the standalone backend.
add larger test for `proc_macro` `FromStr` implementations Currently, there are only few tests that check the output of `TokenStream::from_str` and `Literal::from_str` (which is somewhat understandable as the rustc implementation just delegates these calls to the parser). In preparation for both the standalone backend (rust-lang#130856) which will probably need to reimplement this logic as well as for removing panics from these functions (rust-lang#58736), this PR adds a test which shows the various messy ways of how these functions report errors and the return values for successful parses. Followup PRs such as rust-lang#147859 will change more and more of these "diagnostic + error"s into `LexErrors`. The test structure with the extra module is used to allow reusing it later easily for the standalone backend.
This comment has been minimized.
This comment has been minimized.
6f82492 to
33ff2a3
Compare
| @@ -1378,6 +1378,13 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { | |||
| drop(self); | |||
There was a problem hiding this comment.
Will put the text from my comment above in a discussion so it is not missed:
One final concern I have: Are there any stability guarantees for the Display implementation of
LexError? I'm assuming there wouldn't (or at least shouldn't) be but not exactly sure if/where this is documented.
This PR changes the Display implementation of the type & I'd like to leave the option of improving these messages later open.
|
I'm not very familiar with |
This comment has been minimized.
This comment has been minimized.
33ff2a3 to
519a3f7
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
519a3f7 to
cabd6e7
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
cabd6e7 to
f1c80f5
Compare
Before this PR, calling
TokenStream::from_strorLiteral::from_strwith an invalid argument would always cause a compile error, even if theTokenStreamis not used afterwards at all.This PR changes this so it returns a
LexErrorinstead in some cases.This is very theoretically a breaking change, but the doc comment on the impl already says
Fixes some cases of #58736.